﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StableDiffusionTools.Utils
{
    public static class ExceptionUtil
    {
        public static string FormatInnerExceptions(Exception ex)
        {
            StringBuilder sb = new StringBuilder();
            Exception exception = ex;
            int tabIndex = 0;
            do
            {
                if (tabIndex++ > 0)
                    sb.Append(new string('-', tabIndex - 1) + ">");

                sb.Append(exception.Message);

                if(exception.InnerException != null)
                    sb.AppendLine();

                exception = exception.InnerException;
            } while (exception != null);
            return sb.ToString();
        }
    }
}
